<template>
	<view class="page">
		<image :src="image" mode="widthFix"></image>

		<l-qrcode :value="value" size="600px" :icon="avatar" iconSize="160px" ref="qrcodeRef"></l-qrcode>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: '',
				value: '',
				circle_id: '',
				image: '',
			}
		},
		methods: {
			getCode() {
				const el = this.$refs['qrcodeRef']
				el.canvasToTempFilePath({
					success: (res) => {
						this.image = res.tempFilePath;
					},
					fail(err) {
						console.log('err:::', err)
					}
				})
			},

			getShareUrl() {
				this.$get('/circle.circle/getShareUrl', {
					circle_id: this.circle_id,
				}).then(res => {
					this.avatar = res.data.avatar.replace('http', 'https');
					this.value = res.data.url;
					this.getCode();
				})
			},
		},

		onReady() {

		},

		onLoad(option) {
			if (option.token) {
				uni.setStorageSync('token', option.token);
				uni.setStorageSync('cid', option.cid);
				uni.setStorageSync('terminal', option.terminal);
			}
			this.circle_id = option.circle_id;
			this.getShareUrl();
		}
	}
</script>

<style lang="less" scoped>
	page {
		overflow: hidden;
	}

	.page {
		width: 100vw;
		height: 100vw;
		overflow: hidden;
		padding: 32rpx;

		image {
			width: calc(100vw - 64rpx);
			height: calc(100vw - 64rpx);
		}
	}

	/deep/ .l-qrcode {
		opacity: 0;
	}
</style>